package cn.dnui_xcz826.dnuifood_16110100826.model;


import android.app.Service;

import cn.dnui_xcz826.dnuifood_16110100826.bean.ResultBean;
import cn.dnui_xcz826.dnuifood_16110100826.bean.UserBean;
import cn.dnui_xcz826.dnuifood_16110100826.iface.UserIface;
import cn.dnui_xcz826.dnuifood_16110100826.listener.onRetrofitListener;
import cn.dnui_xcz826.dnuifood_16110100826.service.UserService;
import okhttp3.MultipartBody;
import retrofit2.Call;
import retrofit2.Retrofit;

/**
 * Created by neusoft on 2018/10/15.
 */

public class UserModel extends BaseModel implements UserIface {
    private UserService service;
    @Override
    public void login(String username, String userpass, final onRetrofitListener listener) {
        service=retrofit.create(UserService.class);
        Call<UserBean> call=service.doLogin(username,userpass);
        bindCallback(call,listener,1);
//        call.enqueue(new Callback<UserBean>() {
//            @Override
//            public void onResponse(Call<UserBean> call, Response<UserBean> response) {
//                if (response.body()!=null){
//                    listener.onSuccess(response.body());
//                }
//                else
//                    listener.onFalure("解析有误");
//            }
//
//            @Override
//            public void onFailure(Call<UserBean> call, Throwable t) {
//                listener.onFalure("联网异常！");
//
//            }
//        });

    }

    @Override
    public void register(String username, String userpass, String mobilenum, String address, String comment, onRetrofitListener listener) {
       service=retrofit.create(UserService.class);
        Call<ResultBean> call;
        call=service.doRegister(username,userpass,mobilenum,address,comment);
        bindCallback(call,listener,1);
    }

    @Override
    public void getUserById(String user_id, onRetrofitListener listener) {
        Call call=service.doGetUserById(user_id);
        bindCallback(call,listener,3);
    }

    @Override
    public void updateUserById(String user_id, String username, String userpass, String mobilenum, String address, onRetrofitListener listener) {
        Call call=service.doUpdateUserById(user_id,username,userpass,mobilenum,address);
        bindCallback(call,listener,4);
    }

    @Override
    public void updateAvatar(MultipartBody avatar, onRetrofitListener listener) {
        Call call=service.doUploadAvatar(avatar);
        bindCallback(call,listener,5);

    }



}
